package com.example.dinner;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.ArrayList;

public class FPAdater extends FragmentPagerAdapter {

    ArrayList<Fragment> fragments;
    ArrayList<String> titles;
    public FPAdater(FragmentManager fm) {
        super(fm);
    }

    public FPAdater(FragmentManager fm, ArrayList<Fragment> fragments, ArrayList<String> titles) {
        super(fm);
        this.fragments = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments.size();
    }
    /*让TabLayout能获取到title*/
    @Override
    public CharSequence getPageTitle(int position) {
        return titles.get(position);
    }
}
